<!DOCTYPE html>
<html lang="zh-cn">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		 
			
  
    <meta name="twitter:card" content="summary"/>
    
      <meta name="twitter:image" content="https://www.samrainhan.com/images/avatar.png" />
    
  
  
  <meta name="twitter:title" content="如何提高windows程序的性能"/>
  <meta name="twitter:description" content="调整windows服务器 调整TcpTimedWaitDelay 描述：确定 TCP/IP 可释放已关闭连接并重用其资源前，必须经过的时间。关闭和释放之间的此"/>
  
  
  
  
    <meta name="twitter:creator" content="@韩雨"/>
  



		
		<meta name="author" content="韩雨">
		<meta name="description" content="学习 &amp;nbsp;&amp;bull;&amp;nbsp; 生活">
		<meta name="generator" content="Hugo 0.52" />
		<title>如何提高windows程序的性能 &middot; sam的小窝</title>
		<link rel="shortcut icon" href="https://www.samrainhan.com/images/favicon.ico">
		<link rel="stylesheet" href="https://www.samrainhan.com/css/style.css">
		<link rel="stylesheet" href="https://www.samrainhan.com/css/highlight.css">

		
		<link rel="stylesheet" href="https://www.samrainhan.com/css/font-awesome.min.css">
		

		
		<link href="https://www.samrainhan.com/index.xml" rel="alternate" type="application/rss+xml" title="sam的小窝" />
		

		
	</head>

    <body>
       <nav class="main-nav">
	
	
		<a href='https://www.samrainhan.com/'> <span class="arrow">←</span>Home</a>
	
	<a href='https://www.samrainhan.com/posts'>Archive</a>
	<a href='https://www.samrainhan.com/tags'>Tags</a>
	<a href='https://www.samrainhan.com/about'>About</a>

	

	
	<a class="cta" href="https://www.samrainhan.com/index.xml">Subscribe</a>
	
</nav>


        <section id="wrapper" class="post">
            <article>
                <header>
                    <h1>
                        如何提高windows程序的性能
                    </h1>
                    <h2 class="headline">
                    Dec 26, 2016 00:00
                    · 982 words
                    · 2 minute read
                      <span class="tags">
                      
                      
                          
                              <a href="https://www.samrainhan.com/tags/windows">windows</a>
                          
                              <a href="https://www.samrainhan.com/tags/%E6%80%A7%E8%83%BD">性能</a>
                          
                      
                      
                      </span>
                    </h2>
                </header>
                
                  
                    <div id="toc">
                      <nav id="TableOfContents">
<ul>
<li><a href="#调整windows服务器">调整windows服务器</a>
<ul>
<li><a href="#调整tcptimedwaitdelay">调整TcpTimedWaitDelay</a></li>
<li><a href="#调整maxuserport">调整MaxUserPort</a></li>
</ul></li>
<li><a href="#调整windows-service">调整windows service</a>
<ul>
<li><a href="#配置windows-service的app-config">配置windows service的App.config</a></li>
</ul></li>
</ul>
</nav>
                    </div>
                  
                
                <section id="post-body">
                    

<h1 id="调整windows服务器">调整windows服务器</h1>

<h2 id="调整tcptimedwaitdelay">调整TcpTimedWaitDelay</h2>

<p>描述：确定 TCP/IP 可释放已关闭连接并重用其资源前，必须经过的时间。关闭和释放之间的此时间间隔通称 TIME_WAIT 状态或两倍最大段生命周期（2MSL）状态。此时间期间，重新打开到客户机和服务器的连接的成本少于建立新连接。减少此条目的值允许 TCP/IP 更快地释放已关闭的连接，为新连接提供更多资源。如果运行的应用程序需要快速释放和创建新连接，而且由于 TIME_WAIT 中存在很多连接，导致低吞吐量，则调整此参数。 如何查看或设置： 使用 regedit 命令访问 HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/ Services/TCPIP/Parameters 注册表子键并创建名为 TcpTimedWaitDelay 的新 REG_DWORD 值。 将此值设置为十进制 30，其为十六进制 0x0000001e。该值将等待时间设置为 30 秒。 停止并重新启动系统。 缺省值：0xF0，它将等待时间设置为 240 秒（4 分钟）。 建议值：最小值为 0x1E，它将等待时间设置为 30 秒。</p>

<p>打开注册表编辑器，如 Regedit.exe 或 Regedt32.exe。</p>

<p>导航到：HKLM\System\CurrentControlSet\Services\Tcpip\Parameters</p>

<p>找到 TcpTimedWaitDelay（如果没有就新建一个DWORD），然后将“数值数据” 字段设置为 60（十进制）。</p>

<p>关闭注册表编辑器，然后重新启动计算机。</p>

<h2 id="调整maxuserport">调整MaxUserPort</h2>

<p>描述：确定在应用程序从系统请求可用用户端口时，TCP/IP 可指定的最高端口号。 如何查看或设置： 使用 regedit 命令访问 HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/ Services/TCPIP/Parameters 注册表子键并创建名为 MaxUserPort 的新 REG_DWORD 值。 停止并重新启动系统。 缺省值：无 建议值：至少十进制 32768。</p>

<p>打开注册表编辑器，如 Regedit.exe 或 Regedt32.exe。</p>

<p>导航到：HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters</p>

<p>找到 MaxUserPort （如果没有就新建一个DWORD），將 [数值数据] 字段设置为 60000(十进制)。</p>

<p>关闭注册表编辑器，然后重新启动计算机。</p>

<h1 id="调整windows-service">调整windows service</h1>

<h2 id="配置windows-service的app-config">配置windows service的App.config</h2>

<pre><code>&lt;!-- GcCpuGroup enables Garbage Collection for multiple CPU groups--&gt;
&lt;!-- Thread_UseAllCpuGroups enables manage thread distribution across all CPU groups for the runtime.--&gt;
&lt;configuration&gt;
&lt;runtime&gt;
&lt;Thread_UseAllCpuGroups enabled=&quot;true&quot;/&gt;
&lt;GCCpuGroup enabled=&quot;true&quot;/&gt;
&lt;gcServer enabled=&quot;true&quot;/&gt;
&lt;/runtime&gt;
&lt;/configuration&gt;

&lt;!-- 增加HTTP请求并发数量--&gt;
&lt;system.net&gt;
&lt;connectionManagement&gt;
&lt;add address=&quot;*&quot; maxconnection=&quot;65535&quot;/&gt;
&lt;/connectionManagement&gt;
&lt;/system.net&gt;

&lt;!-- 增加处理线程数量--&gt;
&lt;system.web&gt;
&lt;httpRuntime minFreeThreads=&quot;10240&quot; minLocalRequestFreeThreads=&quot;20480&quot;/&gt;
&lt;processModel autoConfig=&quot;false&quot; maxWorkerThreads=&quot;40960&quot; maxIoThreads=&quot;40960&quot;/&gt;
&lt;/system.web&gt;

&lt;!-- 增加WCF并行处理能力--&gt;
&lt;!-- MaxConcurrentSessions: default is 100 * ProcessorCount--&gt;
&lt;!-- MaxConcurrentCalls: default is 16 * ProcessorCount--&gt;
&lt;!-- MaxConcurrentInstances: default is the total of the above two, which follows the same pattern as before.--&gt;
&lt;serviceThrottling maxConcurrentCalls=&quot;4096&quot; maxConcurrentInstances=&quot;29696&quot; maxConcurrentSessions=&quot;25600 &quot;/&gt; 

&lt;!-- 增加basicHttpBinding的buffer size--&gt;
&lt;basicHttpBinding&gt;
&lt;binding name=&quot;basicHttpBinding&quot; maxReceivedMessageSize=&quot;2147483647&quot; maxBufferPoolSize=&quot;2147483647&quot; maxBufferSize=&quot;2147483647&quot;&gt;
&lt;readerQuotas maxStringContentLength=&quot;8192000&quot;/&gt;
&lt;security mode=&quot;None&quot;/&gt;
&lt;/binding&gt;
&lt;/basicHttpBinding&gt;
</code></pre>

                </section>
            </article>

            
                <a class="twitter" href="https://twitter.com/intent/tweet?text=https%3a%2f%2fwww.samrainhan.com%2fposts%2f2016-12-26-how-to-improve-perfomance-of-windows-service%2f - %e5%a6%82%e4%bd%95%e6%8f%90%e9%ab%98windows%e7%a8%8b%e5%ba%8f%e7%9a%84%e6%80%a7%e8%83%bd "><span class="icon-twitter"> tweet</span></a>

<a class="facebook" href="#" onclick="
    window.open(
      'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href),
      'facebook-share-dialog',
      'width=626,height=436');
    return false;"><span class="icon-facebook-rect"> Share</span>
</a>

            

            
                <div id="disqus_thread"></div>
<script type="text/javascript">
    var disqus_shortname = 'samrainblogbygithub'; 

     
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>

            

            
                <ul id="post-list" class="archive readmore">
    <h3>Read more</h3>

    
    
    
        <li>
            <a href="/posts/2019-04-26-c9-move-to-aws-c9/">Cloud9 Move to Aws C9<aside class="dates">Apr 26 2019</aside></a>
        </li>
    
        <li>
            <a href="/posts/2019-02-16-why-build-blog-with-cloud9/">2019 02 16 Why Build Blog With Cloud9<aside class="dates">Feb 16 2019</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-sports-stretching-best-practices/">运动拉伸最佳实践<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-add-2-files-to-tempdb-for-caching/">给tempdb加2个文件做缓存<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-look-for-sql-server-tables-without-a-clustered-index/">如何找到没有聚集索引的表<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-the-continuous-delivery-maturity-model/">持续实施成熟度模型<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-map-of-continuous-delivery/">持续发布的各个阶段<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-how-dropbox-securely-stores-your-passwords/">Dropbox的用户密码加密机制<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-code-inspection-tool-for-net/">NET代码检查工具<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
        <li>
            <a href="/posts/2018-09-12-how-to-make-unique-id/">怎样生成唯一ID<aside class="dates">Sep 12 2018</aside></a>
        </li>
    
</ul>

            

            <footer id="footer">
    
        <div id="social">

	
	
    <a class="symbol" href="">
        <i class="fa fa-facebook-square"></i>
    </a>
    
    <a class="symbol" href="https://github.com/samrain">
        <i class="fa fa-github-square"></i>
    </a>
    
    <a class="symbol" href="">
        <i class="fa fa-twitter-square"></i>
    </a>
    


</div>

    
    <p class="small">
    
       © Copyright 2019 <i class="fa fa-heart" aria-hidden="true"></i> 韩雨
    
    </p>
    <p class="small">
        Powered by <a href="http://www.gohugo.io/">Hugo</a> Theme By <a href="https://github.com/nodejh/hugo-theme-cactus-plus">nodejh</a>
    </p>
</footer>

        </section>

        <script src="https://www.samrainhan.com/js/jquery-3.3.1.min.js"></script>
<script src="https://www.samrainhan.com/js/main.js"></script>
<script src="https://www.samrainhan.com/js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>




  
<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
	ga('create', 'UA-37708730-1', 'auto');
	
	ga('send', 'pageview');
}
</script>





    </body>
</html>
